﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Documents;
using Hi_Baidu.Entry.CollectionObject;
using System.Windows.Controls;
using Hi_Baidu.ProcessModel;

namespace Hi_Baidu.Timer.TalkMessage
{
    /// <summary>
    ///     提供了关于文字聊天的超时间算和相关操作
    /// </summary>
    class TalkMessageTimeOutEvent : TimeOutEvent
    {
        Friend friend;
        public TalkMessageTimeOutEvent(Friend friend, String Key, int Interval, int TryCount)
            : base(Key, Interval, TryCount)
        {
            this.friend = friend;
            this.OnTryFull += new EventHandler<EventArgs>(TalkMessageTimeOutEvent_OnTryFull);
        }

        void TalkMessageTimeOutEvent_OnTryFull(object sender, EventArgs e)
        {
            Win_TalkWindow win_TalkWindow = Hi_Baidu.Globle.popWindowManager.GetMemberByKey(this.friend.Username) as Win_TalkWindow;
            //找到对应超时聊天窗口，附加超时提示
            if (win_TalkWindow != null)
            {
                System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, new PUBLIC_DELEGATE(Timeout));
            }
        }

        private void Timeout()
        {
            //找到后附加超时信息
            Grid grid = new Grid();
            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions.Add(new RowDefinition());
            grid = ChatViewModel.AppendHead(grid);
            ChatViewModel.AppendMessage(grid, this.friend.Username, "None");
        }
    }
}
